﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Windows.Forms; // for the startup path, bad i know

namespace TranscoderSharp.Coders
{
    public class Flac : Coder, CoderInterface
    {
        static string appFlac= Path.Combine(Application.StartupPath, "flac.exe ");

        #region CoderInterface Members

        public void EncodeWav(AudioFile AudioFile, string WaveFilePath, ConfigObject ConfigObject)
        {
            throw new NotImplementedException();
        }


        public string DecodeToWav(AudioFile InputAudioFile)
        {
            StringBuilder sb = new StringBuilder();

            string TempInputFilePath = InputAudioFile.TempFilePath;
            InputAudioFile.CopyToTempFile();
            string TempOutputFilePath = GetTempWavPath();

            sb.Append("--decode");
            sb.Append(" ");
            sb.Append("\"" + TempInputFilePath + "\"");
            sb.Append(" ");
            sb.Append("-o \"" + TempOutputFilePath + "\"");

            Transcoder.CallExternalProgram(appFlac, sb.ToString(), 5);

            InputAudioFile.Status = AudioFile.EncodingStatus.Decoded;

            // delete temporary input file
            File.Delete(TempInputFilePath);

            return TempOutputFilePath;
        }


        public string GetOutputPath(AudioFile AudioFile)
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}
